package com.pk.platform.business.privilege.service.impl;

import java.util.List;
import java.util.Set;

import com.pk.platform.business.privilege.dao.IRoleDao;
import com.pk.platform.business.privilege.service.IRoleService;
import com.pk.platform.business.privilege.vo.RoleVO;
import com.pk.platform.domain.privilege.Role;
import com.pk.platform.domain.privilege.User;
import com.pk.platform.util.page.ListPage;
import com.pk.platform.util.page.Pager;

public class RoleServiceImpl implements IRoleService {

	private IRoleDao roleDao;
	
	public void addRole(Role role) {
		roleDao.add(role);
	}

	public void delRoles(String[] roleIds) {
		for(String id : roleIds)
		{
			Long roleId = Long.parseLong(id);
			Role role = roleDao.get(Role.class, roleId);
			Set<User> userSet = role.getUserSet();
			for(User user : userSet)
			{
				user.getRoleSet().remove(role);
			}
			roleDao.delete(Role.class, roleId);
		}
	}

	public ListPage queryRole(RoleVO rvo, Pager pager) {
		return roleDao.queryRole(rvo, pager);
	}

	public Role queryRoleById(Long id) {
		return roleDao.get(Role.class, id);
	}

	public void updateRole(Role role) {
		Role r = roleDao.get(Role.class, role.getId());
		r.setRoleName(role.getRoleName());
	}
	
	public List<Role> queryRoleList()
	{
		return roleDao.queryRoleList();
	}
	
	
	

	public IRoleDao getRoleDao() {
		return roleDao;
	}

	public void setRoleDao(IRoleDao roleDao) {
		this.roleDao = roleDao;
	}

}
